package com.leven.printer.sdk.manager;

import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;

import com.leven.printer.sdk.listener.PrinterListener;
import com.leven.printer.sdk.utils.ErrorEnums;
import com.leven.printer.sdk.utils.SdkException;
import com.printer.sdk.PrinterConstants;
import com.printer.sdk.PrinterInstance;

public class PrinterManager {
    protected PrinterInstance myPrinter;
    private PrinterListener printerListener;

    //连接消息回调
    public Handler handler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(@NonNull Message message) {
            switch (message.what) {
                case PrinterConstants.Connect.SUCCESS:
                    //链接成功
                    if(printerListener != null){
                        printerListener.onConnected();
                    }
                    break;
                case PrinterConstants.Connect.FAILED:
                    //连接失败
                    if(printerListener != null){
                        printerListener.onFailed();
                    }
                    break;
                case PrinterConstants.Connect.CLOSED:
                    //关闭连接
                    if(printerListener != null){
                        printerListener.onClose();
                    }
                    break;
                case PrinterConstants.Connect.NODEVICE:
                    if(printerListener != null){
                        printerListener.onNoDevice();
                    }
                    break;
                default:
                    //未知异常
                    if(printerListener != null){
                        printerListener.onUnknownError();
                    }
            }
            return false;
        }
    });

    public void setPrinterListener(PrinterListener printerListener) {
        this.printerListener = printerListener;
    }
}
